#include <bits/stdc++.h>

using namespace std;

const int N = 100010;
pair<int, int> speed[N];
int t, n, m, l, V;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);

    cin >> t;
    while(t --){
        cin >> n >> m >> l >> V;

        int res = 0, tmp = 0;
        for(int  i = 0; i < n; i++){
            int d, v, a;
            cin >> d >> v >> a;
            if(v <= V && a <= 0){
                speed[i] = {d, d};
            }else if(v >= V && a >= 0){
                speed[i] = {d, l};
            }else if(v > V && a < 0){
                int t = (V * V - v * v) / (2 * a);
                speed[i] = {d, min(d + t, l)};
            }else if(v < V && a > 0){
                int t = (V * V - v * v) / (2 * a);
                speed[i] = {min(l, d + t), l};
            }
        }

        sort(speed, speed + n);

        int min_r = 0;
        for(int i = 0; i < n; i++){
            int l = speed[i].first, r = speed[i].second;
            if(l != r){
                if(l >= min_r){
                    tmp ++;
                    min_r = r;
                }else min_r = min(min_r, r);
            }else res ++;
        }
        cout << (n - res) << " " << (n - tmp) << endl;
    }

    return 0;
}
